/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "defaultaccess")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Defaultaccess.findAll", query = "SELECT d FROM Defaultaccess d"),
    @NamedQuery(name = "Defaultaccess.findByRolId", query = "SELECT d FROM Defaultaccess d WHERE d.defaultaccessPK.rolId = :rolId"),
    @NamedQuery(name = "Defaultaccess.findByMenuId", query = "SELECT d FROM Defaultaccess d WHERE d.defaultaccessPK.menuId = :menuId"),
    @NamedQuery(name = "Defaultaccess.findBySubmenuId", query = "SELECT d FROM Defaultaccess d WHERE d.defaultaccessPK.submenuId = :submenuId"),
    @NamedQuery(name = "Defaultaccess.findByOptionId", query = "SELECT d FROM Defaultaccess d WHERE d.defaultaccessPK.optionId = :optionId")})
public class Defaultaccess implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected DefaultaccessPK defaultaccessPK;
    
    @JoinColumns({
        @JoinColumn(name = "menuId", referencedColumnName = "menuId", insertable = false, updatable = false),
        @JoinColumn(name = "submenuId", referencedColumnName = "submenuId", insertable = false, updatable = false),
        @JoinColumn(name = "optionId", referencedColumnName = "optionId", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Option option;
    @JoinColumn(name = "rolId", referencedColumnName = "rolId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Rol rol;

    public Defaultaccess() {
    }

    public Defaultaccess(DefaultaccessPK defaultaccessPK) {
        this.defaultaccessPK = defaultaccessPK;
    }

    public Defaultaccess(int rolId, short menuId, short submenuId, short optionId) {
        this.defaultaccessPK = new DefaultaccessPK(rolId, menuId, submenuId, optionId);
    }

    public DefaultaccessPK getDefaultaccessPK() {
        return defaultaccessPK;
    }

    public void setDefaultaccessPK(DefaultaccessPK defaultaccessPK) {
        this.defaultaccessPK = defaultaccessPK;
    }

    public Option getOption() {
        return option;
    }

    public void setOption(Option option) {
        this.option = option;
    }

    public Rol getRol() {
        return rol;
    }

    public void setRol(Rol rol) {
        this.rol = rol;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (defaultaccessPK != null ? defaultaccessPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Defaultaccess)) {
            return false;
        }
        Defaultaccess other = (Defaultaccess) object;
        if ((this.defaultaccessPK == null && other.defaultaccessPK != null) || (this.defaultaccessPK != null && !this.defaultaccessPK.equals(other.defaultaccessPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Defaultaccess[ defaultaccessPK=" + defaultaccessPK + " ]";
    }
    
}
